package com.cadre.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cadre.common.utils.common.GenerateUUID;
import com.cadre.common.utils.oldutil.DateUtil;
import com.cadre.system.domain.officer.A25;
import com.cadre.system.domain.officer.AssessInfo;
import com.cadre.system.mapper.A25Mapper;
import com.cadre.system.service.AssessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service("assessService")
public class AssessServiceImpl extends ServiceImpl<A25Mapper, A25> implements AssessService {
    @Autowired
    private A25Mapper a25Mapper;

    @Override // com.tdqy.cadre.modular.profess.service.AssessService
    public List<AssessInfo> assessMsg(String personid) {
        List<AssessInfo> assessInfos = new ArrayList<>();
        List<A25> a25s = this.a25Mapper.selectByPersonid(personid);
        if (a25s.size() != 0) {
            for (int i = 0; i < a25s.size(); i++) {
                AssessInfo assessInfo = new AssessInfo();
                assessInfo.setFlowid(a25s.get(i).getFlowid());
                assessInfo.setPersonid(a25s.get(i).getPersonid());
                assessInfo.setA2510(DateUtil.dateToYear(a25s.get(i).getA2510()));
                assessInfo.setA2541(a25s.get(i).getA2541());
                assessInfo.setA2544(a25s.get(i).getA2544());
                assessInfos.add(assessInfo);
            }
        } else {
            System.out.println("-------------------A25 null------------------------");
        }
        return assessInfos;
    }

    @Override // com.tdqy.cadre.modular.profess.service.AssessService
    @Transactional(rollbackFor = {Exception.class})
    public int assessSave(AssessInfo assessInfo) {
        if (assessInfo == null) {
            return 0;
        }
        A25 a25 = new A25();
        a25.setFlowid(GenerateUUID.getUUID());
        a25.setPersonid(assessInfo.getPersonid());
        a25.setA2510(DateUtil.stringtoDate(assessInfo.getA2510(), DateUtil.YEAR_DATE_FORMAT));
        a25.setA2541(assessInfo.getA2541());
        a25.setA2544(assessInfo.getA2544());
        if (this.a25Mapper.insertSelective(a25) == 1) {
            return 1;
        }
        return 0;
    }

    @Override // com.tdqy.cadre.modular.profess.service.AssessService
    public List<A25> selectListByPersonid(String personid) {
        return this.baseMapper.selectByPersonid(personid);
    }
}
